﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RemoteDesktop
{
    internal class TextWidthCalculator
    {
        public static float CalculateTextWidth(string text, Font font)
        {
            using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
            {
                SizeF size = graphics.MeasureString(text, font);
                return size.Width;
            }
        }

        public static void test()
        {
            // 使用示例
            Font myFont = new Font("Arial", 12);
            string myText = "Hello, World!";
            float textWidth = TextWidthCalculator.CalculateTextWidth(myText, myFont);
            Console.WriteLine("Text Width: " + textWidth);
        }
    }
}
